package cn.tedu.boyou.acticle.service.impl;

import cn.tedu.boyou.acticle.domain.TravelCommend;
import cn.tedu.boyou.acticle.mapper.TravelCommendMapper;
import cn.tedu.boyou.acticle.service.ITravelCommendService;
import cn.tedu.boyou.common.query.TravelCommendQuery;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class TravelCommendServiceImpl implements ITravelCommendService{

    @Autowired
    private TravelCommendMapper travelCommendMapper;
    public PageInfo query(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<TravelCommend> list =  travelCommendMapper.selectForList();
        return new PageInfo<>(list);
    }

    public void saveOrUpdate(TravelCommend travelCommend) {
        if(travelCommend.getId()!= null){
            travelCommendMapper.updateByPrimaryKey(travelCommend);
        }else{
            travelCommendMapper.insert(travelCommend);
        }
    }

    public List<TravelCommend> getCommendsByTop5() {
        return travelCommendMapper.selectCommendsByTop5();
    }

}
